<?php
/*
	账户变更记录
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	//余额变更记录
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title','ordersn','fee','status','pay_type','remark','createtime');
	$list=pdo_getslice('core_account_pay_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'账户支付日志'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'ordersn','title'=>'支付单号','type'=>'string'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'statuss'),
			array('name'=>'pay_type','title'=>'支付方式','type'=>'radio','options'=>'pay_types'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','op'=>'detail','title'=>'查看详情'),
		)),
	);
	$return['htmls']=$htmls;
	$return['statuss']=array(
		'0'=>'待支付',
		'1'=>'支付成功',
		'2'=>'支付失败',
	);
	$return['pay_types']=get_pay_types();
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
	$item=pdo_get('core_account_pay_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$statuss=array(
		'0'=>'待支付',
		'1'=>'支付成功',
		'2'=>'支付失败',
	);
	$item['status']=$statuss[$item['status']];
	$pay_types=get_pay_types();
	$item['pay_type']=$pay_types[$item['pay_type']];
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'订单详情',
		'look'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'ordersn','title'=>'支付单号','type'=>'string'),
			array('name'=>'order_id','title'=>'支付发起者订单ID','type'=>'string'),
			array('name'=>'fee','title'=>'订单金额','type'=>'string'),
			array('name'=>'status','title'=>'订单状态','type'=>'string'),
			array('name'=>'pay_type','title'=>'支付方式','type'=>'string'),
			array('name'=>'transaction_id','title'=>'第三方支付单号','type'=>'string'),
			array('name'=>'back_url','title'=>'回调地址','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),
	);
	exi($return);
}
if($_RQ['op']=='del'){
	if($_RQ['del']){
		$del=str_array($_RQ['del']);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=intval($_RQ['id']);
	}
	if(!$del){
		exi('请先选择要删除的订单！','error');
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('core_account_pay_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}